import java.net.MalformedURLException;

import javax.swing.ImageIcon;

public class GravatarIcon {

    private static final String URL = "http://www.gravatar.com/avatar/HASH?s=SIZE&d=identicon&r=pg";

    private int size = 32;
    private String hash;

    public GravatarIcon(String emailHash) {
        hash = emailHash;
    }

    public ImageIcon getImage() {
        try {
            return new ImageIcon(new java.net.URL(URL.replace("HASH", hash).replace("SIZE",
                    "" + size)));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void setSize(int size){
        this.size = size;
    }
    
    public int getSize(){
        return size;
    }
}
